package cn.wyu.validator;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.validation.Valid;

/**
 * Created by ajinlong on 2021/6/26.
 */

@Controller
public class formController {
    @RequestMapping(value = "/form.mvc",method = RequestMethod.GET)
    public String showForm(@ModelAttribute User user)
    {
        return "form";
    }

    @RequestMapping(value = "form.mvc",method = RequestMethod.POST)
    public String process(@ModelAttribute @Valid User user, BindingResult result){
        if(result.hasErrors()){
            return "form";
        }
        return "welcome";
    }
}
